@myrialabs/clopen 0.4.47 → 0.4.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/message-pages.test.ts +163 -0
- package/backend/chat/message-pages.ts +233 -0
- package/backend/chat/stream-manager.ts +91 -67
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/087_create_blob_line_stats.ts +37 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/blob-line-stats-queries.ts +48 -0
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +15 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/env/diff.ts +9 -33
- package/backend/db-client/env/env.test.ts +8 -8
- package/backend/db-client/env/service.ts +1 -1
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/file-watcher.ts +19 -0
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/contributors.test.ts +35 -0
- package/backend/git/contributors.ts +46 -0
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/http/static-assets.test.ts +78 -0
- package/backend/http/static-assets.ts +104 -0
- package/backend/index.ts +32 -16
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +383 -29
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/blob-store.ts +9 -1
- package/backend/snapshot/helpers.ts +3 -11
- package/backend/snapshot/line-stats.test.ts +80 -0
- package/backend/snapshot/line-stats.ts +64 -0
- package/backend/snapshot/restore.ts +252 -0
- package/backend/snapshot/snapshot-service.ts +14 -27
- package/backend/snapshot/turn-changes.test.ts +10 -5
- package/backend/snapshot/turn-changes.ts +78 -40
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +10 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws-wire.test.ts +87 -0
- package/backend/utils/ws-wire.ts +189 -0
- package/backend/utils/ws.ts +101 -192
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +105 -57
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +45 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/log.ts +52 -0
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +78 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +29 -0
- package/backend/ws/preview/watchers.ts +84 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +42 -57
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +12 -13
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/terminal/tunnel.ts +2 -2
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +46 -41
- package/dist/assets/addon-clipboard-wHJhZAA4.js.br +0 -0
- package/dist/assets/addon-clipboard-wHJhZAA4.js.gz +0 -0
- package/dist/assets/addon-fit-DX4qG4td.js.br +1 -0
- package/dist/assets/addon-fit-DX4qG4td.js.gz +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.br +0 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js.gz +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.br +0 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js.gz +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.br +0 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js.gz +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js +7 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.br +0 -0
- package/dist/assets/diff.worker-BoHLxmr2.js.gz +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
- package/dist/assets/{index-CwuKQelV.js → index-CrVWZH_D.js} +1 -1
- package/dist/assets/index-CrVWZH_D.js.br +0 -0
- package/dist/assets/index-CrVWZH_D.js.gz +0 -0
- package/dist/assets/{index-BTcR1byF.js → index-DD0-3EWg.js} +1 -1
- package/dist/assets/index-DD0-3EWg.js.br +0 -0
- package/dist/assets/index-DD0-3EWg.js.gz +0 -0
- package/dist/assets/main-D2_TmcwQ.js +1240 -0
- package/dist/assets/main-D2_TmcwQ.js.br +0 -0
- package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
- package/dist/assets/main-Yucigcmf.css +1 -0
- package/dist/assets/main-Yucigcmf.css.br +0 -0
- package/dist/assets/main-Yucigcmf.css.gz +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.br +0 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js.gz +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.br +0 -0
- package/dist/assets/xterm-B-qIQCd3.js.gz +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.br +0 -0
- package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.gz +0 -0
- package/dist/fonts/dm-sans.css.br +0 -0
- package/dist/fonts/dm-sans.css.gz +0 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/sw.js.br +0 -0
- package/dist/sw.js.gz +0 -0
- package/package.json +3 -3
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +13 -5
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/diff-calculator.test.ts +178 -41
- package/shared/utils/diff-calculator.ts +383 -100
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/process-supervisor.test.ts +172 -0
- package/shared/utils/process-supervisor.ts +251 -0
- package/shared/utils/ws-chunk.test.ts +33 -0
- package/shared/utils/ws-chunk.ts +73 -0
- package/shared/utils/ws-client-chunks.test.ts +45 -0
- package/shared/utils/ws-client.ts +43 -0
- package/shared/utils/ws-server.ts +49 -21
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<img src="https://clopen.myrialabs.dev/images/workspace.webp" alt="Clopen workspace overview" />
|
|
27
27
|
</p>
|
|
28
28
|
|
|
29
|
-
All-in-one workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor. Chat, terminal, git, browser preview, database client, and
|
|
29
|
+
All-in-one workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor. Chat, terminal, git, browser preview, database client, and remote access from any device — plus Skills, Subagents, Commands, and MCP connectors to extend every engine.
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
@@ -58,19 +58,19 @@ A complete development environment designed around AI-assisted workflows, built
|
|
|
58
58
|
|
|
59
59
|
- **Multi-Engine Support** — Switch between Claude Code, OpenCode, Codex, GitHub Copilot, Qwen Code, Pi, Cline, and Cursor as your AI engine, per session
|
|
60
60
|
- **Multi-Account Per Engine** — Manage multiple accounts per engine (personal, work, or team) and switch between them instantly per chat session
|
|
61
|
-
- **Reasoning Effort Control** — Dial a model's thinking level right from the chat input, using that engine's own levels. Set a default per model in Settings, and the choice is remembered and synced
|
|
61
|
+
- **Reasoning Effort Control** — Dial a model's thinking level right from the chat input, using that engine's own levels. Set a default per model in Settings, and the choice is remembered and synced across your devices
|
|
62
62
|
- **Integrated Terminal** — Multi-tab xterm.js terminal with full keyboard control and complete ANSI/VT support, right inside your workspace
|
|
63
63
|
- **Full Git Management** — Stage, commit, branch, push, pull, stash, log, and resolve conflicts, all from a clean UI
|
|
64
64
|
- **Real Browser Preview** — A live browser preview streams directly into your workspace. Interact with your app manually, or let the AI drive: clicking, typing, and scrolling for autonomous visual testing
|
|
65
65
|
- **Database Client** — Connect to PostgreSQL, MySQL, SQLite, MongoDB, and Redis. Browse schemas, run queries, and inspect data, with optional SSH tunneling for databases behind a bastion
|
|
66
66
|
- **Git-Like Checkpoints** — Multi-branch undo/redo with full file snapshots. Roll back to any point in your AI conversation without touching your actual git history
|
|
67
|
-
- **
|
|
67
|
+
- **Remote Access** — Add your phone, tablet, or another computer with a one-time link or QR code. Every device stays in sync live: chats, terminals, and the browser preview
|
|
68
68
|
- **Monaco File Editor** — VS Code's editor right in the browser. Full syntax highlighting, autocomplete, and live file watching, beside your AI chat
|
|
69
69
|
- **Cloudflare Tunnel** — One-click public HTTPS URL for your local dev server. Built-in QR code for instant mobile access. Share your work without deploying
|
|
70
70
|
- **Integrations** — Connect a third-party account once and every engine and project can use it. Credentials are sealed at rest with AES-256-GCM. Includes the full MCP surface: browse the official Model Context Protocol registry, connect with OAuth or custom env/headers, control tool exposure per engine, and sync every connector across all your AI engines
|
|
71
71
|
- **Skills, Commands & Subagents** — Build reusable Skills, slash Commands, delegated Subagents, shared Instructions, and tool Permissions or Profiles once, synced automatically across every engine
|
|
72
|
-
- **Flexible Authentication** — No Login or With Login mode
|
|
73
|
-
- **Stack** — Install AI engines, Git, Chrome, and Cloudflared (for Public Tunnel) from a one-click
|
|
72
|
+
- **Flexible Authentication** — No Login or With Login mode, one-time device pairing links, rate-limited login, and CLI token recovery
|
|
73
|
+
- **Stack** — Install AI engines, Git, Chrome, and Cloudflared (for Public Tunnel) from a one-click panel. Engines install on demand into a clopen-managed directory (`~/.clopen/stack/engines`) — isolated from your global setup, no PATH pollution
|
|
74
74
|
- **Background Processing** — Chat, terminal, and other processes continue running even when you close the browser — come back later and pick up where you left off
|
|
75
75
|
- **Works on Any Device** — Fully responsive across desktop, laptop, tablet, and mobile. Open your workspace from any device and continue exactly where you left off
|
|
76
76
|
|
|
@@ -115,23 +115,23 @@ Starts the server on `http://localhost:9141`.
|
|
|
115
115
|
|
|
116
116
|
On first launch, a setup wizard guides you through:
|
|
117
117
|
|
|
118
|
-
1. **Authentication mode** — Choose between **No Login** (no authentication required, ideal for personal/local use) or **With Login** (login with Personal Access Token,
|
|
119
|
-
2. **
|
|
118
|
+
1. **Authentication mode** — Choose between **No Login** (no authentication required, ideal for personal/local use) or **With Login** (login with a Personal Access Token, recommended when Clopen is reachable from other devices or the internet)
|
|
119
|
+
2. **Account** — If With Login mode is selected, create your account and save the generated PAT
|
|
120
120
|
3. **Stack** — Install Git, Chrome, Cloudflared, and any AI engine you don't have yet — straight from the wizard, no terminal needed
|
|
121
121
|
4. **AI Engines** — Check installation status for every engine and sign in to the ones you'll use. An engine that isn't installed yet links straight back to the Stack step
|
|
122
122
|
5. **Preferences** — Set dark mode, font size, sound notifications, and message layout (Classic cards or Compact lines)
|
|
123
123
|
|
|
124
|
-
You can change the authentication mode anytime in **Settings →
|
|
124
|
+
You can change the authentication mode anytime in **Settings → Sign-in & Devices**.
|
|
125
125
|
|
|
126
|
-
To
|
|
126
|
+
To sign in another of your devices, open **Remote Access → Add a device** and scan the one-time link (valid for 5 minutes).
|
|
127
127
|
|
|
128
|
-
If you lose your
|
|
128
|
+
If you lose your token:
|
|
129
129
|
|
|
130
130
|
```bash
|
|
131
131
|
clopen reset-pat
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
This regenerates and displays a new
|
|
134
|
+
This regenerates and displays a new PAT.
|
|
135
135
|
|
|
136
136
|
---
|
|
137
137
|
|
|
@@ -78,7 +78,7 @@ export const PROJECT_SOURCES: readonly ProjectSource[] = [
|
|
|
78
78
|
{ id: 'cursor-rules', kind: 'instruction', path: '.cursor/rules', layout: 'md-dir', native: [] },
|
|
79
79
|
{ id: 'clinerules', kind: 'instruction', path: '.clinerules', layout: 'file', native: [] },
|
|
80
80
|
|
|
81
|
-
// ── MCP ── `.agents/mcp.json` is Clopen's convention, delivered
|
|
81
|
+
// ── MCP ── `.agents/mcp.json` is Clopen's convention, delivered once it is trusted.
|
|
82
82
|
{ id: 'agents-mcp', kind: 'mcp', path: '.agents/mcp.json', layout: 'file', native: [], editable: true },
|
|
83
83
|
{ id: 'root-mcp', kind: 'mcp', path: '.mcp.json', layout: 'file', native: ['claude'] }
|
|
84
84
|
];
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth Service
|
|
3
3
|
*
|
|
4
|
-
* Core authentication logic
|
|
4
|
+
* Core authentication logic. Clopen has exactly one account — the owner — who
|
|
5
|
+
* signs in from any number of devices; every device is an auth session.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
|
-
import { authQueries
|
|
8
|
+
import { authQueries } from '$backend/database/queries';
|
|
8
9
|
import { readSystemSettings, writeSystemSettings } from '$backend/settings/system-settings';
|
|
9
|
-
import
|
|
10
|
-
import { generateSessionToken, generatePAT, generateInviteToken, generateDeviceCode, hashToken, getTokenType } from './tokens';
|
|
10
|
+
import { generateSessionToken, generatePAT, generateDeviceCode, hashToken, getTokenType } from './tokens';
|
|
11
11
|
import { generateColorFromString, getInitials } from '$backend/utils/user-helpers';
|
|
12
12
|
import { debug } from '$shared/utils/logger';
|
|
13
13
|
|
|
14
14
|
/** Default session lifetime in days */
|
|
15
15
|
const DEFAULT_SESSION_DAYS = 30;
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The owner's account name. Clopen has one account, so nobody is ever asked
|
|
19
|
+
* for a name — the row still needs one.
|
|
20
|
+
*/
|
|
21
|
+
const OWNER_NAME = 'Owner';
|
|
22
|
+
|
|
17
23
|
/** How long a device-pairing code stays claimable before it expires (minutes). */
|
|
18
24
|
const DEVICE_CODE_TTL_MINUTES = 5;
|
|
19
25
|
|
|
@@ -22,7 +28,6 @@ export interface AuthUser {
|
|
|
22
28
|
name: string;
|
|
23
29
|
color: string;
|
|
24
30
|
avatar: string;
|
|
25
|
-
role: 'admin' | 'member';
|
|
26
31
|
createdAt: string;
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -36,13 +41,12 @@ export interface SetupResult extends AuthResult {
|
|
|
36
41
|
personalAccessToken: string;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
function toAuthUser(dbUser: { id: string; name: string; color: string; avatar: string;
|
|
44
|
+
function toAuthUser(dbUser: { id: string; name: string; color: string; avatar: string; created_at: string }): AuthUser {
|
|
40
45
|
return {
|
|
41
46
|
id: dbUser.id,
|
|
42
47
|
name: dbUser.name,
|
|
43
48
|
color: dbUser.color,
|
|
44
49
|
avatar: dbUser.avatar,
|
|
45
|
-
role: dbUser.role,
|
|
46
50
|
createdAt: dbUser.created_at
|
|
47
51
|
};
|
|
48
52
|
}
|
|
@@ -53,8 +57,8 @@ export interface SessionMeta {
|
|
|
53
57
|
ipAddress?: string;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
/** How a session was created — surfaced in the
|
|
57
|
-
export type SessionSource = 'setup' | '
|
|
60
|
+
/** How a session was created — surfaced in the "Your devices" list. */
|
|
61
|
+
export type SessionSource = 'setup' | 'device-link' | 'login' | 'pat' | 'no-auth';
|
|
58
62
|
|
|
59
63
|
function createSessionForUser(userId: string, source: SessionSource, meta?: SessionMeta, sessionDays?: number): { sessionToken: string; expiresAt: string; tokenHash: string } {
|
|
60
64
|
const days = sessionDays ?? DEFAULT_SESSION_DAYS;
|
|
@@ -79,7 +83,7 @@ function createSessionForUser(userId: string, source: SessionSource, meta?: Sess
|
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
/**
|
|
82
|
-
* Check if the system needs initial setup (
|
|
86
|
+
* Check if the system needs initial setup (the owner does not exist yet)
|
|
83
87
|
*/
|
|
84
88
|
export function needsSetup(): boolean {
|
|
85
89
|
return authQueries.countUsers() === 0;
|
|
@@ -109,12 +113,12 @@ export function getOnboardingState(): OnboardingState {
|
|
|
109
113
|
if (stored.onboarding === 'complete' || stored.onboardingComplete === true) return 'complete';
|
|
110
114
|
if (stored.onboarding === 'pending') return 'pending';
|
|
111
115
|
|
|
112
|
-
// No marker at all. An install that already has
|
|
113
|
-
// been through setup — the wizard is what created
|
|
116
|
+
// No marker at all. An install that already has an owner has, by
|
|
117
|
+
// definition, been through setup — the wizard is what created it. Record that so a
|
|
114
118
|
// single missing key can never flap the whole instance back to setup.
|
|
115
119
|
if (!needsSetup()) {
|
|
116
120
|
markOnboardingComplete();
|
|
117
|
-
debug.log('auth', 'Onboarding marker missing but
|
|
121
|
+
debug.log('auth', 'Onboarding marker missing but the owner exists — recorded as complete');
|
|
118
122
|
return 'complete';
|
|
119
123
|
}
|
|
120
124
|
|
|
@@ -140,42 +144,36 @@ export function markOnboardingComplete(): void {
|
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
/**
|
|
143
|
-
*
|
|
144
|
-
* Does not generate a PAT (not needed for no-auth).
|
|
145
|
-
* If users already exist, returns the first admin.
|
|
147
|
+
* Sign in for no-auth mode: reuse the owner, creating a default one on a fresh
|
|
148
|
+
* install. Does not generate a PAT (not needed for no-auth).
|
|
146
149
|
*/
|
|
147
|
-
export function
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const { sessionToken, expiresAt } = createSessionForUser(existingAdmin.id, 'no-auth');
|
|
153
|
-
debug.log('auth', `No-auth mode: reusing existing admin: ${existingAdmin.name} (${existingAdmin.id})`);
|
|
150
|
+
export function createOrGetNoAuthOwner(): AuthResult {
|
|
151
|
+
const existing = authQueries.getOwner();
|
|
152
|
+
if (existing) {
|
|
153
|
+
const { sessionToken, expiresAt } = createSessionForUser(existing.id, 'no-auth');
|
|
154
|
+
debug.log('auth', `No-auth mode: reusing owner: ${existing.name} (${existing.id})`);
|
|
154
155
|
return {
|
|
155
|
-
user: toAuthUser(
|
|
156
|
+
user: toAuthUser(existing),
|
|
156
157
|
sessionToken,
|
|
157
158
|
expiresAt
|
|
158
159
|
};
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
// Create default admin
|
|
162
162
|
const userId = `user-${crypto.randomUUID()}`;
|
|
163
163
|
const now = new Date().toISOString();
|
|
164
|
-
const defaultName = 'Admin';
|
|
165
164
|
|
|
166
165
|
const dbUser = authQueries.createUser({
|
|
167
166
|
id: userId,
|
|
168
|
-
name:
|
|
169
|
-
color: generateColorFromString(
|
|
170
|
-
avatar: getInitials(
|
|
171
|
-
role: 'admin',
|
|
167
|
+
name: OWNER_NAME,
|
|
168
|
+
color: generateColorFromString(OWNER_NAME),
|
|
169
|
+
avatar: getInitials(OWNER_NAME),
|
|
172
170
|
personal_access_token_hash: '', // No PAT for no-auth mode
|
|
173
171
|
created_at: now
|
|
174
172
|
});
|
|
175
173
|
|
|
176
174
|
const { sessionToken, expiresAt } = createSessionForUser(userId, 'no-auth');
|
|
177
175
|
|
|
178
|
-
debug.log('auth', `No-auth mode: created
|
|
176
|
+
debug.log('auth', `No-auth mode: created the owner (${userId})`);
|
|
179
177
|
|
|
180
178
|
return {
|
|
181
179
|
user: toAuthUser(dbUser),
|
|
@@ -185,17 +183,11 @@ export function createOrGetNoAuthAdmin(): AuthResult {
|
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
/**
|
|
188
|
-
* Create the
|
|
189
|
-
* Only works when no users exist.
|
|
186
|
+
* Create the owner account (setup flow). Only works before setup.
|
|
190
187
|
*/
|
|
191
|
-
export function
|
|
188
|
+
export function createOwner(meta?: SessionMeta): SetupResult {
|
|
192
189
|
if (!needsSetup()) {
|
|
193
|
-
throw new Error('Setup already completed.
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const trimmedName = name.trim();
|
|
197
|
-
if (trimmedName.length === 0) {
|
|
198
|
-
throw new Error('Name cannot be empty');
|
|
190
|
+
throw new Error('Setup already completed. The owner account exists.');
|
|
199
191
|
}
|
|
200
192
|
|
|
201
193
|
const userId = `user-${crypto.randomUUID()}`;
|
|
@@ -205,91 +197,16 @@ export function createAdmin(name: string, meta?: SessionMeta): SetupResult {
|
|
|
205
197
|
|
|
206
198
|
const dbUser = authQueries.createUser({
|
|
207
199
|
id: userId,
|
|
208
|
-
name:
|
|
209
|
-
color: generateColorFromString(
|
|
210
|
-
avatar: getInitials(
|
|
211
|
-
role: 'admin',
|
|
200
|
+
name: OWNER_NAME,
|
|
201
|
+
color: generateColorFromString(OWNER_NAME),
|
|
202
|
+
avatar: getInitials(OWNER_NAME),
|
|
212
203
|
personal_access_token_hash: patHash,
|
|
213
204
|
created_at: now
|
|
214
205
|
});
|
|
215
206
|
|
|
216
207
|
const { sessionToken, expiresAt } = createSessionForUser(userId, 'setup', meta);
|
|
217
208
|
|
|
218
|
-
debug.log('auth', `
|
|
219
|
-
|
|
220
|
-
return {
|
|
221
|
-
user: toAuthUser(dbUser),
|
|
222
|
-
sessionToken,
|
|
223
|
-
expiresAt,
|
|
224
|
-
personalAccessToken: pat
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Create a user from an invite token
|
|
230
|
-
*/
|
|
231
|
-
export function createUserFromInvite(rawInviteToken: string, name: string, meta?: SessionMeta): SetupResult {
|
|
232
|
-
const trimmedName = name.trim();
|
|
233
|
-
if (trimmedName.length === 0) {
|
|
234
|
-
throw new Error('Name cannot be empty');
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const inviteHash = hashToken(rawInviteToken);
|
|
238
|
-
const invite = authQueries.getInviteByTokenHash(inviteHash);
|
|
239
|
-
|
|
240
|
-
if (!invite) {
|
|
241
|
-
throw new Error('Invalid invite token');
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Check expiry
|
|
245
|
-
if (invite.expires_at && new Date(invite.expires_at) < new Date()) {
|
|
246
|
-
throw new Error('Invite token has expired');
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Check max uses
|
|
250
|
-
if (invite.max_uses > 0 && invite.use_count >= invite.max_uses) {
|
|
251
|
-
throw new Error('Invite token has reached maximum uses');
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Only allow creating member role from invite (single admin policy)
|
|
255
|
-
const role: 'admin' | 'member' = 'member';
|
|
256
|
-
|
|
257
|
-
const userId = `user-${crypto.randomUUID()}`;
|
|
258
|
-
const now = new Date().toISOString();
|
|
259
|
-
const pat = generatePAT();
|
|
260
|
-
const patHash = hashToken(pat);
|
|
261
|
-
|
|
262
|
-
const dbUser = authQueries.createUser({
|
|
263
|
-
id: userId,
|
|
264
|
-
name: trimmedName,
|
|
265
|
-
color: generateColorFromString(trimmedName),
|
|
266
|
-
avatar: getInitials(trimmedName),
|
|
267
|
-
role,
|
|
268
|
-
personal_access_token_hash: patHash,
|
|
269
|
-
created_at: now
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
// Increment invite use count
|
|
273
|
-
authQueries.incrementUseCount(invite.id);
|
|
274
|
-
|
|
275
|
-
// Apply any projects the admin pre-selected when creating the invite, so the
|
|
276
|
-
// new member has access the moment they join (no separate assignment trip).
|
|
277
|
-
if (invite.project_ids) {
|
|
278
|
-
try {
|
|
279
|
-
const projectIds: string[] = JSON.parse(invite.project_ids);
|
|
280
|
-
for (const projectId of projectIds) {
|
|
281
|
-
if (projectQueries.getById(projectId) && !projectQueries.userHasProject(userId, projectId)) {
|
|
282
|
-
projectQueries.addUserProject(userId, projectId);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
} catch (err) {
|
|
286
|
-
debug.warn('auth', 'Failed to apply invite project pre-assignment:', err);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const { sessionToken, expiresAt } = createSessionForUser(userId, 'invite', meta);
|
|
291
|
-
|
|
292
|
-
debug.log('auth', `User created from invite: ${trimmedName} (${userId}), role: ${role}`);
|
|
209
|
+
debug.log('auth', `Owner account created (${userId})`);
|
|
293
210
|
|
|
294
211
|
return {
|
|
295
212
|
user: toAuthUser(dbUser),
|
|
@@ -376,104 +293,11 @@ export function getUserById(id: string): AuthUser | null {
|
|
|
376
293
|
}
|
|
377
294
|
|
|
378
295
|
/**
|
|
379
|
-
*
|
|
380
|
-
*/
|
|
381
|
-
export function listUsers(): AuthUser[] {
|
|
382
|
-
return authQueries.getAllUsers().map(toAuthUser);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Remove a user (prevents removing the last admin)
|
|
387
|
-
*/
|
|
388
|
-
export function removeUser(userId: string): void {
|
|
389
|
-
const user = authQueries.getUserById(userId);
|
|
390
|
-
if (!user) {
|
|
391
|
-
throw new Error('User not found');
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
if (user.role === 'admin' && authQueries.countAdmins() <= 1) {
|
|
395
|
-
throw new Error('Cannot remove the last admin');
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// Delete all sessions for this user
|
|
399
|
-
authQueries.deleteSessionsByUserId(userId);
|
|
400
|
-
// Delete the user (cascade will handle invite_tokens.created_by)
|
|
401
|
-
authQueries.deleteUser(userId);
|
|
402
|
-
|
|
403
|
-
debug.log('auth', `User removed: ${user.name} (${userId})`);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Create an invite token
|
|
408
|
-
*/
|
|
409
|
-
export function createInvite(
|
|
410
|
-
createdBy: string,
|
|
411
|
-
options: { label?: string; maxUses?: number; expiresInMinutes?: number; projectIds?: string[] }
|
|
412
|
-
): { inviteToken: string; invite: ReturnType<typeof authQueries.getInviteByTokenHash> } {
|
|
413
|
-
const rawToken = generateInviteToken();
|
|
414
|
-
const tokenHash = hashToken(rawToken);
|
|
415
|
-
const now = new Date().toISOString();
|
|
416
|
-
|
|
417
|
-
const expiresAt = options.expiresInMinutes
|
|
418
|
-
? new Date(Date.now() + options.expiresInMinutes * 60 * 1000).toISOString()
|
|
419
|
-
: null;
|
|
420
|
-
|
|
421
|
-
// Keep only project ids that actually exist so a stale pick can't wedge the join.
|
|
422
|
-
const validProjectIds = (options.projectIds ?? []).filter((id) => projectQueries.getById(id));
|
|
423
|
-
|
|
424
|
-
const invite = authQueries.createInvite({
|
|
425
|
-
id: `invite-${crypto.randomUUID()}`,
|
|
426
|
-
token_hash: tokenHash,
|
|
427
|
-
role: 'member',
|
|
428
|
-
label: options.label ?? null,
|
|
429
|
-
created_by: createdBy,
|
|
430
|
-
max_uses: options.maxUses ?? 1,
|
|
431
|
-
use_count: 0,
|
|
432
|
-
expires_at: expiresAt,
|
|
433
|
-
created_at: now,
|
|
434
|
-
project_ids: validProjectIds.length ? JSON.stringify(validProjectIds) : null
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
debug.log('auth', `Invite created by ${createdBy}: ${invite.id}`);
|
|
438
|
-
|
|
439
|
-
return { inviteToken: rawToken, invite };
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* Validate an invite token (without using it)
|
|
296
|
+
* The owner account, or null before setup.
|
|
444
297
|
*/
|
|
445
|
-
export function
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
if (!invite) {
|
|
450
|
-
return { valid: false, error: 'Invalid invite token' };
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
if (invite.expires_at && new Date(invite.expires_at) < new Date()) {
|
|
454
|
-
return { valid: false, error: 'Invite has expired' };
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
if (invite.max_uses > 0 && invite.use_count >= invite.max_uses) {
|
|
458
|
-
return { valid: false, error: 'Invite has reached maximum uses' };
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return { valid: true, role: invite.role };
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* List all invites
|
|
466
|
-
*/
|
|
467
|
-
export function listInvites() {
|
|
468
|
-
return authQueries.getAllInvites();
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* Revoke an invite
|
|
473
|
-
*/
|
|
474
|
-
export function revokeInvite(id: string): void {
|
|
475
|
-
authQueries.revokeInvite(id);
|
|
476
|
-
debug.log('auth', `Invite revoked: ${id}`);
|
|
298
|
+
export function getOwner(): AuthUser | null {
|
|
299
|
+
const user = authQueries.getOwner();
|
|
300
|
+
return user ? toAuthUser(user) : null;
|
|
477
301
|
}
|
|
478
302
|
|
|
479
303
|
/**
|
|
@@ -591,30 +415,7 @@ export function revokeDeviceCode(userId: string, rawCode: string): boolean {
|
|
|
591
415
|
}
|
|
592
416
|
|
|
593
417
|
/**
|
|
594
|
-
*
|
|
595
|
-
*/
|
|
596
|
-
export function updateUserName(userId: string, newName: string): AuthUser {
|
|
597
|
-
const trimmedName = newName.trim();
|
|
598
|
-
if (trimmedName.length === 0) {
|
|
599
|
-
throw new Error('Name cannot be empty');
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
authQueries.updateUser(userId, {
|
|
603
|
-
name: trimmedName,
|
|
604
|
-
color: generateColorFromString(trimmedName),
|
|
605
|
-
avatar: getInitials(trimmedName)
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
const updated = authQueries.getUserById(userId);
|
|
609
|
-
if (!updated) {
|
|
610
|
-
throw new Error('User not found after update');
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return toAuthUser(updated);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Logout all sessions (all users)
|
|
418
|
+
* Sign out every device
|
|
618
419
|
*/
|
|
619
420
|
export function logoutAllSessions(): number {
|
|
620
421
|
const count = authQueries.deleteAllSessions();
|
|
@@ -623,62 +424,8 @@ export function logoutAllSessions(): number {
|
|
|
623
424
|
}
|
|
624
425
|
|
|
625
426
|
/**
|
|
626
|
-
*
|
|
627
|
-
|
|
628
|
-
export function listUserProjects(userId: string): Project[] {
|
|
629
|
-
const user = authQueries.getUserById(userId);
|
|
630
|
-
if (!user) {
|
|
631
|
-
throw new Error('User not found');
|
|
632
|
-
}
|
|
633
|
-
return projectQueries.getAllForUser(userId);
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
/**
|
|
637
|
-
* Assign a project to a user. Admins are implicitly assigned to all projects
|
|
638
|
-
* they create, but this is used to grant a member access to a project.
|
|
639
|
-
* Returns true if a new assignment was added, false if user already had access.
|
|
640
|
-
*/
|
|
641
|
-
export function assignProjectToUser(userId: string, projectId: string): boolean {
|
|
642
|
-
const user = authQueries.getUserById(userId);
|
|
643
|
-
if (!user) {
|
|
644
|
-
throw new Error('Access denied');
|
|
645
|
-
}
|
|
646
|
-
const project = projectQueries.getById(projectId);
|
|
647
|
-
if (!project) {
|
|
648
|
-
throw new Error('Access denied');
|
|
649
|
-
}
|
|
650
|
-
if (projectQueries.userHasProject(userId, projectId)) {
|
|
651
|
-
return false;
|
|
652
|
-
}
|
|
653
|
-
projectQueries.addUserProject(userId, projectId);
|
|
654
|
-
debug.log('auth', `Project ${projectId} assigned to user ${userId}`);
|
|
655
|
-
return true;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Revoke a user's access to a project. Refuses to remove the last admin
|
|
660
|
-
* association to avoid orphaning the project.
|
|
661
|
-
*/
|
|
662
|
-
export function unassignProjectFromUser(userId: string, projectId: string): boolean {
|
|
663
|
-
const user = authQueries.getUserById(userId);
|
|
664
|
-
if (!user) {
|
|
665
|
-
throw new Error('Access denied');
|
|
666
|
-
}
|
|
667
|
-
const project = projectQueries.getById(projectId);
|
|
668
|
-
if (!project) {
|
|
669
|
-
throw new Error('Access denied');
|
|
670
|
-
}
|
|
671
|
-
if (!projectQueries.userHasProject(userId, projectId)) {
|
|
672
|
-
return false;
|
|
673
|
-
}
|
|
674
|
-
projectQueries.removeUserProject(userId, projectId);
|
|
675
|
-
debug.log('auth', `Project ${projectId} unassigned from user ${userId}`);
|
|
676
|
-
return true;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* List a user's active auth sessions (devices). `current` marks the session
|
|
681
|
-
* matching the given token hash so the caller can flag "this device".
|
|
427
|
+
* A signed-in device. `current` marks the session matching the given token
|
|
428
|
+
* hash so the caller can flag "this device".
|
|
682
429
|
*/
|
|
683
430
|
export interface AuthSessionInfo {
|
|
684
431
|
id: string;
|
|
@@ -693,16 +440,8 @@ export interface AuthSessionInfo {
|
|
|
693
440
|
source: string | null;
|
|
694
441
|
}
|
|
695
442
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
userId: string;
|
|
699
|
-
userName: string;
|
|
700
|
-
userColor: string;
|
|
701
|
-
userRole: 'admin' | 'member';
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
export function listUserSessions(userId: string, currentTokenHash?: string, onlineHashes?: Set<string>): AuthSessionInfo[] {
|
|
705
|
-
return authQueries.getSessionsByUserId(userId).map((s) => ({
|
|
443
|
+
export function listSessions(currentTokenHash?: string, onlineHashes?: Set<string>): AuthSessionInfo[] {
|
|
444
|
+
return authQueries.getAllSessions().map((s) => ({
|
|
706
445
|
id: s.id,
|
|
707
446
|
createdAt: s.created_at,
|
|
708
447
|
lastActiveAt: s.last_active_at,
|
|
@@ -716,57 +455,16 @@ export function listUserSessions(userId: string, currentTokenHash?: string, onli
|
|
|
716
455
|
}
|
|
717
456
|
|
|
718
457
|
/**
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
*/
|
|
722
|
-
export function listAllSessions(currentTokenHash?: string, onlineHashes?: Set<string>): AdminSessionInfo[] {
|
|
723
|
-
return authQueries.getAllSessions().map((s) => {
|
|
724
|
-
const user = authQueries.getUserById(s.user_id);
|
|
725
|
-
return {
|
|
726
|
-
id: s.id,
|
|
727
|
-
createdAt: s.created_at,
|
|
728
|
-
lastActiveAt: s.last_active_at,
|
|
729
|
-
expiresAt: s.expires_at,
|
|
730
|
-
current: currentTokenHash !== undefined && s.token_hash === currentTokenHash,
|
|
731
|
-
online: onlineHashes?.has(s.token_hash) ?? false,
|
|
732
|
-
userAgent: s.user_agent,
|
|
733
|
-
ipAddress: s.ip_address,
|
|
734
|
-
source: s.source,
|
|
735
|
-
userId: s.user_id,
|
|
736
|
-
userName: user?.name ?? 'Unknown',
|
|
737
|
-
userColor: user?.color ?? '#888888',
|
|
738
|
-
userRole: user?.role ?? 'member'
|
|
739
|
-
};
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* Revoke one of a user's own sessions by id. Scoped to the owner so a member
|
|
745
|
-
* can only sign out their own devices. Returns the deleted session's token hash
|
|
746
|
-
* so the caller can kick any live WS connection bound to it.
|
|
747
|
-
*/
|
|
748
|
-
export function revokeUserSession(userId: string, sessionId: string): { success: boolean; tokenHash?: string } {
|
|
749
|
-
const session = authQueries.getSessionById(sessionId);
|
|
750
|
-
if (!session || session.user_id !== userId) {
|
|
751
|
-
return { success: false };
|
|
752
|
-
}
|
|
753
|
-
authQueries.deleteSession(sessionId);
|
|
754
|
-
debug.log('auth', `Session revoked: ${sessionId} (user ${userId})`);
|
|
755
|
-
return { success: true, tokenHash: session.token_hash };
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
/**
|
|
759
|
-
* Revoke any session by id (admin-only). Unlike revokeUserSession this is not
|
|
760
|
-
* owner-scoped — an admin can sign out any connected device. Returns the token
|
|
761
|
-
* hash so the caller can kick the live WS connection immediately.
|
|
458
|
+
* Sign out one device. Returns the deleted session's token hash so the caller
|
|
459
|
+
* can kick any live WS connection bound to it.
|
|
762
460
|
*/
|
|
763
|
-
export function
|
|
461
|
+
export function revokeSession(sessionId: string): { success: boolean; tokenHash?: string } {
|
|
764
462
|
const session = authQueries.getSessionById(sessionId);
|
|
765
463
|
if (!session) {
|
|
766
464
|
return { success: false };
|
|
767
465
|
}
|
|
768
466
|
authQueries.deleteSession(sessionId);
|
|
769
|
-
debug.log('auth', `Session revoked
|
|
467
|
+
debug.log('auth', `Session revoked: ${sessionId}`);
|
|
770
468
|
return { success: true, tokenHash: session.token_hash };
|
|
771
469
|
}
|
|
772
470
|
|
|
@@ -774,19 +472,15 @@ export function revokeAnySession(sessionId: string): { success: boolean; tokenHa
|
|
|
774
472
|
* Remote Access sidebar indicator: the number of *other* devices currently
|
|
775
473
|
* online. "Active" means a live WS connection is bound to the session right now
|
|
776
474
|
* — not merely a session row in the DB — so this mirrors Public Tunnel's live
|
|
777
|
-
* connection count and the "
|
|
778
|
-
*
|
|
779
|
-
* is always excluded so the badge reads "N remote devices connected".
|
|
475
|
+
* connection count and the "Your devices" list. The viewer's current device is
|
|
476
|
+
* excluded so the badge reads "N remote devices connected".
|
|
780
477
|
*/
|
|
781
478
|
export function getRemoteAccessSummary(
|
|
782
|
-
userId: string,
|
|
783
|
-
isAdmin: boolean,
|
|
784
479
|
onlineHashes: Set<string>,
|
|
785
480
|
currentTokenHash?: string
|
|
786
481
|
): { activeConnections: number } {
|
|
787
|
-
const sessions = isAdmin ? authQueries.getAllSessions() : authQueries.getSessionsByUserId(userId);
|
|
788
482
|
let activeConnections = 0;
|
|
789
|
-
for (const s of
|
|
483
|
+
for (const s of authQueries.getAllSessions()) {
|
|
790
484
|
if (!onlineHashes.has(s.token_hash)) continue;
|
|
791
485
|
if (currentTokenHash && s.token_hash === currentTokenHash) continue;
|
|
792
486
|
activeConnections++;
|
|
@@ -15,7 +15,7 @@ import { getOnboardingState, markOnboardingComplete } from './auth-service';
|
|
|
15
15
|
import { readSystemSettings, writeSystemSettings, SYSTEM_SETTINGS_KEY } from '../settings/system-settings';
|
|
16
16
|
import { getClopenDir } from '../utils/paths';
|
|
17
17
|
import { authQueries, settingsQueries } from '../database/queries';
|
|
18
|
-
import { initializeDatabase, closeDatabase } from '../database';
|
|
18
|
+
import { initializeDatabase, closeDatabase, getDatabase } from '../database';
|
|
19
19
|
|
|
20
20
|
let testUserId: string;
|
|
21
21
|
let originalSettings: string | null = null;
|
|
@@ -32,14 +32,13 @@ beforeAll(async () => {
|
|
|
32
32
|
name: 'Onboarding Test User',
|
|
33
33
|
color: '#000000',
|
|
34
34
|
avatar: 'OT',
|
|
35
|
-
role: 'admin',
|
|
36
35
|
personal_access_token_hash: `hash-${randomUUID()}`,
|
|
37
36
|
created_at: new Date().toISOString()
|
|
38
37
|
});
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
afterAll(() => {
|
|
42
|
-
|
|
41
|
+
getDatabase().prepare('DELETE FROM users WHERE id = ?').run(testUserId);
|
|
43
42
|
if (originalSettings === null) {
|
|
44
43
|
settingsQueries.delete(SYSTEM_SETTINGS_KEY);
|
|
45
44
|
} else {
|